package com.yanqu.road.server.manger.activity.share;

import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.share.config.ShareConfig;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.server.TempMgr;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.share.ShareModule;
import com.yanqu.road.server.manger.activity.NormalActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;
import java.util.Map;

public class ShareActivityMgr extends TempMgr {

    private static ShareConfig shareConfig;
    private static String saveDeskReward;
    private static String scylReward;
    private static String qyfxShareMaxPerson;
    private static ActivityInfo qyfxActivityInfo;
    private static String dyBackReward;


    public static void reloadActivityData(){
        getLogger().info("reload share Activity start");
        // 活动信息 activityInfo
        List<ActivityInfo> openActivityInfoList = NormalActivityMgr.getOpenActivityInfoList(eActivityType.SHARE.getValue());
        if (openActivityInfoList.size() == 0) {
            getLogger().info("no share Activity in show time");
            return;
        }
        for (ActivityInfo activityInfo : openActivityInfoList) {
            int activityId = activityInfo.getActivityId();
            if (activityInfo.getChildType() == 1) { //呼朋唤友
                ShareConfig tmpConfig = new ShareConfig();
                tmpConfig.setActivityId(activityId);
                tmpConfig.setActivityInfo(activityInfo);

                // 其他配置
                Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityId);
                tmpConfig.setShareCD(Integer.parseInt(activityConfigMap.get("WXLG_SHARE_CD").getValue()));
                tmpConfig.setShareDailyLimit(Integer.parseInt(activityConfigMap.get("WXLG_SHARE_DAY_LIMIT").getValue()));
                tmpConfig.setShareDayMaxPerson(Integer.parseInt(activityConfigMap.get("WXLG_SHARE_MAX_PERSON").getValue()));
                tmpConfig.setShareReward(activityConfigMap.get("WXLG_SHARE_REWARD").getValue());
                tmpConfig.setInvitationCD(activityConfigMap.get("WXLG_INVITE_CD").getIntValue());
                // 设置config
                shareConfig = tmpConfig;
            } else if (activityInfo.getChildType() == 2) {  //保存桌面
                Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityId);
                saveDeskReward = activityConfigMap.get("BCZM_SHARE_REWARD").getValue();
            } else if (activityInfo.getChildType() == 3) { //收藏有礼
                Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityId);
                scylReward = activityConfigMap.get("SCYL_SHARE_REWARD").getValue();
            } else if (activityInfo.getChildType() == 4) { //亲友分享
                Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityId);
                qyfxShareMaxPerson = activityConfigMap.get("QYFX_SHARE_MAX_PERSON").getValue();
                qyfxActivityInfo = activityInfo;
                for (GamePlayer player : GamePlayerMgr.getCopyPlayerMap().values()) {
                    player.getModule(ShareModule.class).initUserData(activityId);
                    player.getModule(ShareModule.class).syncUserData();
                }
            }else if (activityInfo.getChildType() == 6) { //抖音回到游戏
                Map<String, ActivityConfig> activityConfigMap = NormalActivityMgr.getActivityConfigMap(activityId);
                dyBackReward = activityConfigMap.get("WXLG_BACK_REWARD").getValue();
            }
        }
        getLogger().info("reload share Activity finish");

    }

    public static ActivityInfo getOpenActivityInfo() {
        if (shareConfig == null) {
            return null;
        }
        return shareConfig.getActivityInfo();
    }

    public static ActivityInfo getQyfxActivityInfo() {
        return qyfxActivityInfo;
    }

    public static ShareConfig getConfig() {
        return shareConfig;
    }

    public static String getSaveDeskReward() {
        return saveDeskReward;
    }

    public static String getScylReward() {
        return scylReward;
    }

    public static String getDyBackReward() {
        return dyBackReward;
    }

    public static int getQyfxShareMaxPerson() {
        if (!StringUtils.isNullOrEmpty(qyfxShareMaxPerson)) {
            return Integer.parseInt(qyfxShareMaxPerson);
        }
        return 0;
    }

    @Override
    public boolean reloadConfig() throws Exception {
        return true;
    }

    @Override
    public boolean reloadData() throws Exception {
        return true;
    }

    @Override
    public boolean init() throws Exception {
        return reload();
    }

    @Override
    public boolean stop() {
        return true;
    }



}
